package org.blogsomy.controller;

import java.io.IOException;
import java.io.Writer;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.code.lightsomy.annotations.Action;
import com.google.code.lightsomy.annotations.Controller;
import com.google.code.lightsomy.output.Renderer;

@Controller(layout = "/view/layout.tpl")
public class PostController extends BaseController {
	
	@Action
	public void list(HttpServletRequest req, HttpServletResponse res) {
		Renderer r = Renderer.getRenderer(Renderer.Type.VELOCITY, req, res);
		r.set("posts", getDaoFacade().getPostDao().getAll());
		r.output(r.render());
	}
	
	@Action
	public void create(HttpServletRequest req, HttpServletResponse res) {
	}
	
	@Action
	public void read(HttpServletRequest req, HttpServletResponse res) throws IOException {
		Writer writer = res.getWriter();
		writer.append("year: " + req.getParameter("year"))
			.append("<br/>month: " + req.getParameter("month"))
			.append("<br/>day: " + req.getParameter("day"))
			.append("<br/>title: " + req.getParameter("title"))
			.flush();
	}
	
	@Action
	public void update(HttpServletRequest req, HttpServletResponse res) {
		
	}
	
	@Action
	public void delete(HttpServletRequest req, HttpServletResponse res) {
		
	}
}
